﻿using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;

namespace IsPay.Logic
{
    public class CommonFormat
    {
        public static DataTable JasonToDataTable(String edittablejasn)
        {
            JArray ja = (JArray)Newtonsoft.Json.JsonConvert.DeserializeObject(edittablejasn);
            int irow = 0;
            DataTable dt = new DataTable();
            foreach (JObject jobj in ja)
            {

                if (irow == 0)
                {
                    foreach (JProperty pry in jobj.Properties())
                    {
                        dt.Columns.Add(pry.Name.ToUpper());
                    }

                }
                DataRow drnew = dt.NewRow();
                foreach (JProperty pryv in jobj.Properties())
                {
                    drnew[pryv.Name.ToUpper()] = pryv.Value;
                }
                dt.Rows.Add(drnew);
                irow++;
            }
            return dt;
        }
    }
}